<?php

class {$className} extends f_core_Action
{ldelim}
	public function execute()
	{ldelim}
		$formProvider = f_form_Provider::getInstance();
		
		$formProvider->setDocumentName("{$documentName}")
		            ->setModuleName("{$moduleName}")
		            ->setFormName("Form{$documentName|capitalize}");
		
		$values = $formProvider->getParams();
		
		if($formProvider->isSubmitted())
		{ldelim}
			if($formProvider->isValid())
			{ldelim}
				${$documentName} = {$object}::createNew();
				
				{$fields}
			{rdelim}
			else
			{ldelim}
				$values['errors'] = $formProvider->getErrors();
			{rdelim}
		{rdelim}
					
{if isset($docFields)} 
		// Retrieve field of type "document"
		$docFields = unserialize('{$docFields}');
		
		if(count($docFields) > 0)
		{ldelim}
			$documentProvider = f_document_Provider::getInstance();
			$relatedDocs = array();
			
			// For each document field
			foreach($docFields as $currentDoc)
			{ldelim}
				// Retrieve columns data from currentDoc to populate the selectbox fields
				$columns = array("document_uid",$currentDoc["foreignField"]);
				$relatedDocs[$currentDoc["name"]] = $documentProvider->loadDocuments($currentDoc['type'])->retrieveColumnValues($columns);
			{rdelim}
			$values['relatedDocs'] = $relatedDocs;
		{rdelim}
{/if}		
		$this->setModel($values);
		$this->setView('success');
	{rdelim}	
	
	public function validate()
	{ldelim}
		return true;
	{rdelim}
	
	public function errorHandler()
	{ldelim}
		$this->setView('error');
	{rdelim}
{rdelim}